package com.vvv.method;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author vvv
 * @date 2023-10-16 15 00
 * discription
 */
public class ReentrantLockDemo02 {
    public static final ReentrantLock lock = new ReentrantLock();
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
           if (!lock.tryLock()) {
               System.out.println("获取立刻失败");
               return;
           }
           try {
               System.out.println("do something ...");
           } finally {
               lock.unlock();
           }
        }, "t1");

        System.out.println("main线程获得锁");
        lock.lock();
        t1.start();
    }
}
